﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Bukovics.Workflow.Hosting;
using CommonLibrary.DataModel.Basic;

namespace AspWebTest
{
    public partial class Approval : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //頁面加載
            this.SqlDataSource2.SelectParameters["ID"].DefaultValue = Session["UserID"].ToString();
        }

        protected void Button_wait2do_Click(object sender, EventArgs e)
        {
            //待辦工作
            this.GridView2.DataSourceID = null;
            this.GridView2.DataSource = wait2do("未处理", int.Parse(Session["UserID"].ToString()));
            this.GridView2.DataBind();
        }

        protected void Button_alreaydo_Click(object sender, EventArgs e)
        {
            //已辦工作
            this.GridView2.DataSourceID = null;
            this.GridView2.DataSource = wait2do("已处理", int.Parse(Session["UserID"].ToString()));
            this.GridView2.DataBind();
        }

        protected void Button_newdo_Click(object sender, EventArgs e)
        {
            //新建工作
            this.GridView1.DataSourceID = "SqlDataSource1";
        }

        private DataTable wait2do(string state,int userid)
        {
            string str = "select * from ((SELECT     dbo.wf_task.task_id,dbo.wf_task.ptask_id,dbo.wf_task.uniqueid, dbo.wf_task.taskname, dbo.wf_task.state, dbo.wf_task.processtype, dbo.system_users.id, dbo.system_users.name, " +
                      " dbo.system_users.duty_id"+
                      " FROM         dbo.system_users INNER JOIN"+
                      " dbo.wf_task ON dbo.system_users.id = dbo.wf_task.user_id"+
                      " WHERE     (dbo.wf_task.state = N'"+state+"') AND (dbo.wf_task.processtype = N'按人员')) union"+
                      "(SELECT     dbo.wf_task.task_id,dbo.wf_task.ptask_id,dbo.wf_task.uniqueid, dbo.wf_task.taskname, dbo.wf_task.state, dbo.wf_task.processtype, dbo.system_users.id, dbo.system_users.name, " +
                      " dbo.system_users.duty_id" +
                      " FROM         dbo.system_users INNER JOIN" +
                      " dbo.wf_task ON dbo.system_users.id = dbo.wf_task.user_id" +
                      " WHERE     (dbo.wf_task.state = N'" + state + "') AND (dbo.wf_task.processtype = N'发起人')) union" +
                      "(SELECT     dbo.wf_task.task_id,dbo.wf_task.ptask_id,dbo.wf_task.uniqueid, dbo.wf_task.taskname, dbo.wf_task.state, dbo.wf_task.processtype,  dbo.system_users.id, dbo.system_users.name," +
                      " dbo.system_users.duty_id"+
                      " FROM         dbo.system_users INNER JOIN"+
                      " dbo.system_dutys ON dbo.system_users.duty_id = dbo.system_dutys.id INNER JOIN"+
                      " dbo.wf_task ON dbo.system_dutys.id = dbo.wf_task.user_id"+
                      " WHERE     (dbo.wf_task.state = N'" + state + "') AND (dbo.wf_task.processtype = N'按职务'))) a where a.id=" + userid;
            return CommonLibrary.DB.DBExecuteUtil.querySqlTable(str);
        }
    }
}
